﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using GeoFinderClientApp.ViewModel;
using GeoFinderClientApp.Model;

namespace GeoFinderClientApp
{
    public partial class MainPage : PhoneApplicationPage
    {
        private ViewModels vm;
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            vm = new ViewModels();            
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            var hasOptions = vm.HasSavedPushOptions();
            Connect.Content = hasOptions ? "Connect to Facebook" : "First choose\nPush notifications\noptions";
            Connect_Click(this, null);
        }

        private void Options_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/View/Settings.xaml", UriKind.Relative));
        }

        private void Connect_Click(object sender, RoutedEventArgs e)
        {
            if (vm.HasSavedPushOptions())
            {
                NavigationService.Navigate(new Uri("/View/FacebookLogin.xaml", UriKind.Relative));
            }
            else
            {
                NavigationService.Navigate(new Uri("/View/FirstLogin.xaml", UriKind.Relative));
            }
        }

    }
}